package cn.plushine.service;

import cn.plushine.mapper.BasePOrderMapper;
import cn.plushine.mapper.BaseSOrderMapper;
import cn.plushine.pojo.Goods;
import cn.plushine.pojo.POrder;
import cn.plushine.pojo.POrderItem;
import cn.plushine.pojo.SOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;


/**
 * 销售订单接口实现类
 */
@Service
public class BaseSOrderServiceImpl implements BaseSOrderService {

    @Autowired
    BaseSOrderMapper baseSOrderMapper;

    // 获取销售订单
    @Override
    public List<SOrder> get() {
        return baseSOrderMapper.get();
    }

    // 查询货物出库价格、单位和库存
    @Override
    public Goods getUnit(int id) {
        return baseSOrderMapper.getUnit(id);
    }

    // 添加销售订单
    @Override
    public int addSOrder(String id, Date date, int salesperson, String inputId, int customer) {
        return baseSOrderMapper.addSOrder(id, date, salesperson, inputId, customer);
    }

    // 修改货物信息（销售订单id、销售价格、货物id、销售数目）
    @Override
    public int modify(String id, BigDecimal outPrice, int goodsId, int num) throws Exception {
        int modifyDB = baseSOrderMapper.modify(id, outPrice, goodsId, num);
        if (modifyDB != 0) {
            return modifyDB;
        }
        throw new Exception("修改货物信息（销售订单id、销售价格、货物id、销售数目）失败！");
    }

    // 取消销售订单
    @Override
    public int cancel(String id) {
        return baseSOrderMapper.cancel(id);
    }

    // 恢复货物信息（绑定的销售订单为null）
    @Override
    public int recover(String id) {
        return baseSOrderMapper.recover(id);
    }
}
